﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Pacol
{
    public class Missile
    {
        public double[] _position = new double[2];

        public Vector2 _force;
        public Game1.Direction _direction;

        private double _elapsedTime;
        private double _speed;

        Texture2D _textMissile;

        public Color _color;

        public object _proprietary;

        public Missile(double[] position, Game1.Direction direction, Texture2D textMissile, Color color, object proprietary)
        {
            _color = color;
            _speed = Game1._blockSize * 0.01;

            _position[Game1.x] = (int)position[Game1.x];
            _position[Game1.y] = (int)position[Game1.y];

            //set the direction of the missile
            if (direction == Game1.Direction.up)
                _force = new Vector2(0, - (float)_speed);
            if (direction == Game1.Direction.down)
                _force = new Vector2(0, (float)_speed);
            if (direction == Game1.Direction.left)
                _force = new Vector2(-(float)_speed, 0);
            if (direction == Game1.Direction.right)
                _force = new Vector2((float)_speed, 0);

            _textMissile = textMissile;

            _direction = direction;

            _proprietary = proprietary;
        }

        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public void Update(GameTime gameTime)
        {
            _elapsedTime = gameTime.ElapsedGameTime.TotalMilliseconds;

            //update the position of the missile
            _position[Game1.x] += _force.X * _elapsedTime;
            _position[Game1.y] += _force.Y * _elapsedTime;
        }

        /// <summary>
        /// This is called when the player should draw itself.
        /// </summary>
        /// <param name="blocSize">size of all the bloc (with wall)</param>
        public void Draw(SpriteBatch spriteBatch, int blocSize)
        {
            spriteBatch.Draw(_textMissile, new Rectangle((int)_position[Game1.x], (int)_position[Game1.y], blocSize, blocSize), new Rectangle(0, (int)this._direction * 25, 25, 25), Color.White);
        }

        /// <summary>
        /// Return the rectangle where is placed the missile.
        /// </summary>
        /// <returns></returns>
        public Rectangle getRect()
        {
            return new Rectangle((int)_position[Game1.x] + Game1._blockSize / 2, (int)_position[Game1.y] + Game1._blockSize / 2, Game1._blockSize / 4, Game1._blockSize / 4);
        }
    }
}
